package com.boc.langxiang.presenter.adm;


import com.boc.langxiang.contract.adm.AdmListContract;
import com.boc.langxiang.entity.request.AdmListRequest;
import com.boc.langxiang.entity.response.AdmEntity;
import com.boc.langxiang.entity.response.AdmListContent;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.net.ApiService;
import com.boc.langxiang.net.HandleErrorSubscriber;
import com.boc.langxiang.net.NetClient;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * CreateTime: 2016-06-14上午10:40
 * Author: wjkjinke00@126.com
 * Description:
 */
public class AdmListPresenter implements AdmListContract.Presenter {

    private final ApiService mService;
    private AdmListContract.View mView;

    public AdmListPresenter(AdmListContract.View view) {
        mService = NetClient.getInstance().net().create(ApiService.class);
        mView = view;
    }


    @Override
    public void admList(int page, String type) {
        mView.showLoading();
        AdmListRequest request = new AdmListRequest();
        request.page = page;
        request.type = type;
        mService.admList(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<AdmListContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<AdmListContent> response) {
                        List<AdmEntity> res = response.getContent().getRes();
                        mView.admListSuccess(res);
                    }
                });
    }
}
